package com.firebird.app.fekpsl.ui.activity.sword.rank

import android.graphics.Color
import android.os.Bundle
import androidx.fragment.app.Fragment
import androidx.viewpager.widget.ViewPager.OnPageChangeListener
import com.firebird.app.fekpsl.R
import com.firebird.app.fekpsl.adapter.sword.rank.ViewPagerAdapter
import com.firebird.app.fekpsl.base.BaseTbActivity
import com.firebird.app.fekpsl.ui.fragment.sword.rank.MemberRandFriendFragment
import com.firebird.app.fekpsl.ui.fragment.sword.rank.MemberRandWorldFragment
import com.flyco.tablayout.listener.OnTabSelectListener
import kotlinx.android.synthetic.main.layout_toolbar.*
import kotlinx.android.synthetic.main.sword_rank_member_rand_rank.*

class MemberRandRankActivity : BaseTbActivity() {
    private var mList:List<Fragment>?=null
    private var mViewPagerAdapter: ViewPagerAdapter?=null

    override fun onCreate(savedInstanceState: Bundle?) {
        super.onCreate(savedInstanceState)
        initView()
        setItem()
        setTab()
    }
    private fun initView(){
        setContentView(R.layout.sword_rank_member_rand_rank)
        initViewTitle()
    }
    fun initViewTitle(){
        val drawable = resources.getDrawable(com.firebird.app.fekpsl.R.drawable.back)
        drawable.setBounds(0, 0, 120, 120)
        tv_back.setCompoundDrawables(drawable, null, null, null)
        setBack()
        val titleName = this.resources.getText(com.firebird.app.fekpsl.R.string.member_rand_rank) as String
        setTitle(titleName)
    }
    private fun setTab(){
        val tab1:MemberRandFriendFragment= MemberRandFriendFragment()
        val tab2:MemberRandWorldFragment= MemberRandWorldFragment()
        var list= listOf<Fragment>(tab1,tab2)
        vp_content.adapter= ViewPagerAdapter(supportFragmentManager,list)

        tl_table.setOnTabSelectListener(object :OnTabSelectListener{
            override fun onTabSelect(position: Int) {
                vp_content.currentItem = position
            }

            override fun onTabReselect(position: Int) {}
        })
        //tl_table.setupWd
        vp_content.addOnPageChangeListener(object : OnPageChangeListener {
            override fun onPageScrolled(i: Int, v: Float, i1: Int) {}
            override fun onPageSelected(i: Int) {
                tl_table.setCurrentTab(i)
            }
            override fun onPageScrollStateChanged(i: Int) {}
        })
    }
    fun setItem(){
        //val list= listOf<String>("好友", "世界")
        val mTitles = arrayOf("好友", "世界")
        tl_table.setTabData(mTitles)
        tl_table.setIndicatorCornerRadius(10f);//设置圆角
        tl_table.setTextSelectColor(Color.WHITE);//选中文字颜色
        tl_table.setTextUnselectColor(Color.parseColor("#007AFF"));//未选中文字颜色
        tl_table.setIndicatorColor(Color.parseColor("#007AFF"));//选中区域颜色
        tl_table.setDividerColor(Color.parseColor("#007AFF"));//设置分割线颜色
        tl_table.setIndicatorMargin(1f,1f,1f,1f);//设置内间距
    }
}
